package com.aop.Aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

/**
 * Created by win10 on 2020/2/6 17:55
 * 开启动态代理
 */
@EnableAspectJAutoProxy(proxyTargetClass = true)
@Aspect
@Component
public class MyAspect {
    /**
     * 连接点 编写规则：
     * execution(* com.spring.aop.impl.orderimpl.*(..))
     * execution ： 关键字
     * （* ） 代表任意返回值
     * （* com.spring.aop.impl.orderimpl） 代表指定的包
     * (* com.spring.aop.impl.orderimpl.* 代表指定的包下的所有方法
     * (* com.spring.aop.impl.orderimpl.*(..))  代表指定的包下的所有方法并且任意参数
     */
    @Before("execution(* com.aop.impl.OrderImpl.*(..))")
    public void before() {
        System.out.println("前置增强===========");
    }

    @After("point()")
    public void after() {
        System.out.println("后置增强===========");
    }

    @AfterReturning(value = "point()")
    public void afterReturning() {
        System.out.println("正常返回=========== > ");
    }

    @AfterThrowing(value = "point()", throwing = "e")
    public void afterThrowing(Exception e) {
        System.out.println("异常===========");
    }

    @Around("point()")
    public void around(ProceedingJoinPoint point) throws Throwable {
        System.out.println(point.getSignature().getName());
        Object proceed = point.proceed();
        System.out.println("环绕===========");
    }

    @Pointcut("execution(* com.aop.impl.OrderImpl.*(..))")
    public void point() {

    }


}
